package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.web.admin.service.FileService;
import io.minio.errors.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * Created by 小可乐$ on 2024/8/13$ 9:11$
 * description: 图片上传的文件管理
 */
@Tag(name = "文件管理")
@RestController
@RequestMapping("/admin/file")
public class FileUploadController {
    @Autowired
    private FileService fileService;
    /**
     * 上传图片
     * */
    @Operation(summary = "上传图片")
    @PostMapping("upload")
    public Result<String> uploadFile(@RequestBody MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
//        String返回一个url路径名
        String url = null;

        url = fileService.uploadFile(file);

        return Result.ok(url);
    }
}